import React, {Component} from 'react';
import MytableInput from '../../components/Mytableinput'
import Select from '../../components/Select'
import './Shangpinguanli.css'
import axios from 'axios';
import {SELECT_DATA} from '../../utils/api'

class Shangpinguanli extends Component {
    constructor() {
        super();
        this.state = {
            tableData:[]
        }
    }
    abc(id){
        console.log(id);
    }
    selectData(e){
        axios({
            url:SELECT_DATA,
            method:'get',
            params:{
                goods_id:e.goodsId,
                goods_name:e.goodsName,
                goods_shelves_id:e.goodsState
            }
        }).then(data=>{
            this.setState({
                tableData:data.data.data
            })
        })
    }
    selectTableData(){
        axios({
            url: SELECT_DATA,
            method: 'get',
            data: {}
        }).then(data=>{
            this.setState({
                tableData:data.data.data
            });
        })
    }
    componentDidMount (){
        this.selectTableData()
    }
    componentWillReceiveProps(nextProps, nextContext) {
        this.setState({
            tableData:nextProps.tableData
        })
    }
    componentDidUpdate (){}
    render() {
        let table = this.state.tableData.length ? <MytableInput mydata={this.state.tableData}/> : "";
        return (
            <div id='app'>
                <div id='select'>
                    <h3 className='liebiao'>商品筛选</h3>
                    <Select onData={this.selectData.bind(this)}/>
                </div>
                <div id='table'>
                    <h3 className='liebiao'>商品列表</h3>
                    {table}
                </div>
            </div>
        );
    }


}

export default Shangpinguanli;

























